package com.evil.formula.pojo.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
@NoArgsConstructor
public class CalcReqDTO {
    /**
     * 公式
     */
    @NotBlank(message = "公式不能为空")
    private String formula;
    /**
     * 用户信息
     */
    private UserInfo userInfo;
    /**
     * 扩展信息
     */
    private ExtendInfo extendInfo;

    public CalcReqDTO(String formula) {
        this.formula = formula;
    }

    @Data
    @AllArgsConstructor
    public static class UserInfo {
        private String nickName;
        private String tel;
    }

    @Data
    public static class ExtendInfo {
        private Map<Long, DeptInfo> deptInfos;
        private Map<Long, MemberInfo> memberInfos;

        public ExtendInfo() {
            this.deptInfos = new HashMap<>();
            this.memberInfos = new HashMap<>();
        }

        public void putDept(Long id, String name) {
            this.deptInfos.put(id, new DeptInfo(id, name));
        }

        public void putMember(Long id, String nickName, String tel) {
            this.memberInfos.put(id, new MemberInfo(nickName, tel));
        }

        /**
         * 部门信息
         */
        @Data
        @AllArgsConstructor
        public static class DeptInfo {
            private Long id;
            private String name;
        }

        /**
         * 成员信息
         */
        @Data
        @AllArgsConstructor
        public static class MemberInfo {
            private String nickName;
            private String tel;
        }
    }
}
